Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Utilities Usage Examples #288

Open
wants to merge 1 commit into
base: usage-examples
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using SplashKitSDK;

namespace Program
{
public class Program
{
public static void Main()
{
// Display a dialog to the user
SplashKit.DisplayDialog("Welcome!", "Hello, this is a simple dialog message.", SplashKit.GetSystemFont(), 20);

// Display another dialog with a different message and font size
SplashKit.DisplayDialog("Second Message", "This is another dialog with a different message.", SplashKit.GetSystemFont(), 25);

// Display a dialog with a different title and message
SplashKit.DisplayDialog("Third Message", "This is a dialog with BIG TEXT!", SplashKit.GetSystemFont(), 40);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some sort of issue with the display_dialog function that isn't showing the last dialog box. I've tested a few things and I think it has something to do with the length of the message because when I put in a few more characters in like "This is another dialog with BIG TEXT!" it works fine.

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using static SplashKitSDK.SplashKit;

// Display a dialog to the user
DisplayDialog("Welcome!", "Hello, this is a simple dialog message.", GetSystemFont(), 20);

// Display another dialog with a different message and font size
DisplayDialog("Second Message", "This is another dialog with a different message.", GetSystemFont(), 25);

// Display a dialog with a different title and message
DisplayDialog("Third Message", "This is a dialog with BIG TEXT!", GetSystemFont(), 40);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "splashkit.h"

int main()
{
// Display a dialog to the user
display_dialog("Welcome!", "Hello, this is a simple dialog message.", get_system_font(), 20);

// Display another dialog with a different message and font size
display_dialog("Second Message", "This is another dialog with a different message.", get_system_font(), 25);

// Display a dialog with a different title and message
display_dialog("Third Message", "This is a dialog with BIG TEXT!", get_system_font(), 40);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from splashkit import *

# Display a dialog to the user
display_dialog("Welcome!", "Hello, this is a simple dialog message.", get_system_font(), 20)

# Display another dialog with a different message and font size
display_dialog("Second Message", "This is another dialog with a different message.", get_system_font(), 25)

# Display a dialog with a different title and message
display_dialog("Third Message", "This is a dialog with BIG TEXT!", get_system_font(), 40)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Display Dialog Boxes

The following code shows an example of using [display dialog](/api/utilities/#display-dialog) to show 3 different dialog boxes, each with the font size increasing to show how they can be used to display different sizes of text or messages.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using SplashKitSDK;

namespace Program
{
public class Program
{
public static void Main()
{
SplashKit.WriteLine("Welcome to the Simple Calculator!");
SplashKit.WriteLine("You can add or subtract two numbers.\n");

while (true)
{
SplashKit.WriteLine("Enter the first number (or type 'exit' to quit):");
string input1 = SplashKit.ReadLine();

// Check for exit condition
if (SplashKit.ToLowercase(input1) == "exit")
{
break;
}

// Validate the first number
if (!SplashKit.IsNumber(input1))
{
SplashKit.WriteLine("Oops! That's not a valid number. Please try again.\n");
continue;
}

string input2 = "";

// Loop until the second number is valid
bool validSecondNumber = false;

while (!validSecondNumber)
{
SplashKit.WriteLine("Enter the second number:");
input2 = SplashKit.ReadLine();

// Validate the second number
if (!SplashKit.IsNumber(input2))
{
SplashKit.WriteLine("Oops! That's not a valid number. Please try again.\n");
}
else
{
validSecondNumber = true;
}
}

SplashKit.WriteLine("Enter the operation (+ or -):");
string operation = SplashKit.ReadLine();

// Check for valid operation
if (operation != "+" && operation != "-")
{
SplashKit.WriteLine("Invalid operation. Please enter '+' or '-' only.\n");
continue;
}

// Convert inputs to double
double num1 = SplashKit.ConvertToDouble(input1);
double num2 = SplashKit.ConvertToDouble(input2);

// Perform the operation
if (operation == "+")
{
SplashKit.WriteLine("Result: " + (num1 + num2) + "\n");
}
else if (operation == "-")
{
SplashKit.WriteLine("Result: " + (num1 - num2) + "\n");
}
}

SplashKit.WriteLine("Thank you for using the Simple Calculator!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using static SplashKitSDK.SplashKit;

WriteLine("Welcome to the Simple Calculator!");
WriteLine("You can add or subtract two numbers.\n");

while (true)
{
WriteLine("Enter the first number (or type 'exit' to quit):");
string input1 = ReadLine();

// Check for exit condition
if (input1.ToLower() == "exit")
{
break;
}

// Validate the first number
if (!IsNumber(input1))
{
WriteLine("Oops! That's not a valid number. Please try again.\n");
continue;
}

string input2 = "";

// Loop until the second number is valid
bool validSecondNumber = false;
while (!validSecondNumber)
{
WriteLine("Enter the second number:");
input2 = ReadLine();

// Validate the second number
if (!IsNumber(input2))
{
WriteLine("Oops! That's not a valid number. Please try again.\n");
}
else
{
validSecondNumber = true;
}
}

WriteLine("Enter the operation (+ or -):");
string operation = ReadLine();

// Check for valid operation
if (operation != "+" && operation != "-")
{
WriteLine("Invalid operation. Please enter '+' or '-' only.\n");
continue;
}

// Convert inputs to double
double num1 = ConvertToDouble(input1);
double num2 = ConvertToDouble(input2);

// Perform the operation
if (operation == "+")
{
WriteLine("Result: " + (num1 + num2) + "\n");
}
else if (operation == "-")
{
WriteLine("Result: " + (num1 - num2) + "\n");
}
}

WriteLine("Thank you for using the Simple Calculator!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "splashkit.h"

int main()
{
write_line("Welcome to the Simple Calculator!");
write_line("You can add or subtract two numbers.\n");

string input1, input2, operation;

while (true)
{
write_line("Enter the first number (or type 'exit' to quit):");
input1 = read_line();

// Check for exit condition
if (to_lowercase(input1) == "exit")
{
break;
}

// Validate the first number
if (!is_number(input1))
{
write_line("Oops! That's not a valid number. Please try again.\n");
continue;
}

// Loop until the second number is valid
bool valid_second_number = false;
while (!valid_second_number)
{
write_line("Enter the second number:");
input2 = read_line();

// Validate the second number
if (!is_number(input2))
{
write_line("Oops! That's not a valid number. Please try again.\n");
}
else
{
valid_second_number = true;
}
}

write_line("Enter the operation (+ or -):");
operation = read_line();

// Check for valid operation
if (operation != "+" && operation != "-")
{
write_line("Invalid operation. Please enter '+' or '-' only.\n");
continue;
}

// Convert inputs to double
double num1 = convert_to_double(input1);
double num2 = convert_to_double(input2);

// Perform the operation
if (operation == "+")
{
write_line("Result: " + std::to_string(num1 + num2)+ "\n");
}
else if (operation == "-")
{
write_line("Result: " + std::to_string(num1 - num2)+ "\n");
}
}

write_line("Thank you for using the Simple Calculator!");
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from splashkit import *

write_line("Welcome to the Simple Calculator!")
write_line("You can add or subtract two numbers.\n")

while True:
write_line("Enter the first number (or type 'exit' to quit):")
input1 = read_line()

# Check for exit condition
if to_lowercase(input1) == "exit":
break

# Validate the first number
if not is_number(input1):
write_line("Oops! That's not a valid number. Please try again.\n")
continue

# Loop until the second number is valid
valid_second_number = False
while not valid_second_number:
write_line("Enter the second number:")
input2 = read_line()

# Validate the second number
if not is_number(input2):
write_line("Oops! That's not a valid number. Please try again.\n")
else:
valid_second_number = True

write_line("Enter the operation (+ or -):")
operation = read_line()

# Check for valid operation
if operation != "+" and operation != "-":
write_line("Invalid operation. Please enter '+' or '-' only.\n")
continue

# Convert inputs to double
num1 = convert_to_double(input1)
num2 = convert_to_double(input2)

# Perform the operation
if operation == "+":
write_line("Result: " + str(num1 + num2) + "\n")
elif operation == "-":
write_line("Result: " + str(num1 - num2) + "\n")

write_line("Thank you for using the Simple Calculator!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Number Calculator

The following code shows examples of using [is number](/api/utilities/#is-number) function to perform addition and subtraction operations. It includes input validation to ensure that the entered values are numbers.
37 changes: 37 additions & 0 deletions public/usage-examples/utilities/split/split-1-sentence-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using SplashKitSDK;

namespace Program
{
public class Program
{
public static void Main()
{
// Prompt user for input string and delimiter
SplashKit.Write("Enter a string to split: ");
string text = SplashKit.ReadLine();

SplashKit.Write("Enter a delimiter character: ");
string delimiterInput = SplashKit.ReadLine();

// Ensure the delimiter is a single character
if (delimiterInput.Length != 1)
{
SplashKit.WriteLine("Please enter a single character as the delimiter.");
}
else
{
char delimiter = delimiterInput[0];

// Split the input string
List<string> result = SplashKit.Split(text, delimiter);

// Display the split substrings
SplashKit.WriteLine("Split result:");
foreach (string part in result)
{
SplashKit.WriteLine($"- {part}");
}
}
}
}
}
Loading