Skip to content
Snippets Groups Projects
Commit ab7581c8 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

Kentanmuokkaus string-taulukoksi

parent ab0c419f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ using System;
using Jypeli;
/// @author Vesa Lappalainen
/// @version 16.10.2012
/// @version 17.10.2021
///
/// <summary>
/// Ohjelmassa harjoitellaan 2-ulotteisen
......@@ -24,13 +24,13 @@ public class KentanMuokkaus : PhysicsGame
// SetWindowSize(1000, 700);
Level.Width = 100;
Level.Height = 100;
char[,] kentta = {
{'P', '.', 'P'},
{'.', 'O', 'n'},
{'n', '.', 'P'},
{'O', ' ', 'P'},
string[] kentta = {
"P.P",
".On",
"n.P",
"O P",
};
// Gravity = new Vector(0, -1000);
TeeKentta(kentta);
AsetaOhjaimet();
......@@ -44,7 +44,7 @@ public class KentanMuokkaus : PhysicsGame
/// avulla. Kutsutaan aliohjelmia eri merkeille luotujen merkitysten
/// perusteella.
/// </summary>
public void TeeKentta(char[,] kentta)
public void TeeKentta(string[] kentta)
{
double alkuX = Level.Left + KOKO / 2 + 20;
double alkuY = Level.Top - KOKO / 2;
......@@ -57,12 +57,12 @@ public class KentanMuokkaus : PhysicsGame
// etta tietyt merkit vastaavat tietyn kentalle lisattavan olion
// aliohjelmakutsua. Myos koordinaatit saadaan matriisista:
// Rivi toimii x-koordinaattina, ja sarake y-koordinaattina.
for (int iy = 0; iy < kentta.GetLength(0); iy++)
for (int iy = 0; iy < kentta.Length; iy++)
{
double x = alkuX;
for (int ix = 0; ix < kentta.GetLength(1); ix++)
for (int ix = 0; ix < kentta[iy].Length; ix++)
{
char t = kentta[iy, ix];
char t = kentta[iy][ix];
switch (t)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment